/**
 * 请求前缀，后面后台添加网关后需要前缀选择微服务
 */
import { fallbackRequestGet, fallbackRequestPost } from '@/utils/Request'

const URL_PREFIX = 'middle-goods/'

/**
 * 获取商品类别信息，结果表示为一棵树
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const queryGoodGroupTree = (successCallback = null, fullCallback = null) => {
  return fallbackRequestGet(URL_PREFIX + 'good_group/queryTree', {}, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, null, fullCallback)
}

/**
 * 添加一个商品分组
 * @param {GoodGroupInsertDTO} goodGroupInsertDTO 新添加的商品分组数据
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const insertGoodGroup = (goodGroupInsertDTO, successCallback = null, fullCallback = null) => {
  return fallbackRequestPost(URL_PREFIX + 'good_group/insertGoodGroup', goodGroupInsertDTO, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, null, fullCallback)
}

/**
 * 更新一个商品分组
 * @param {GoodGroupUpdateDTO} goodGroupUpdateDTO 需要更新的商品分组数据
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const updateGoodGroup = (goodGroupUpdateDTO, successCallback = null, fullCallback = null) => {
  return fallbackRequestPost(URL_PREFIX + 'good_group/updateGoodGroup', goodGroupUpdateDTO, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, null, fullCallback)
}

/**
 * 根据id删除商品分组，只删除该节点，其子节点全部放到父节点中去
 * @param {String|Number} id 商品分组id
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const removeGoodGroupById = (id, successCallback = null, fullCallback = null) => {
  return fallbackRequestGet(URL_PREFIX + 'good_group/removeGoodGroupById', { id }, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, null, fullCallback)
}

/**
 * 根据id删除商品分组，只删除该节点，其子节点全部放到父节点中去
 * @param {Array<String|Number>} ids 商品分组id
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const removeGoodGroupByIds = (ids, successCallback = null, fullCallback = null) => {
  return fallbackRequestPost(URL_PREFIX + 'good_group/removeGoodGroupByIds', ids, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, null, fullCallback)
}
